// SingleEntityOperation.cpp: implementation of the SingleEntityOperation class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "SingleEntityOperation.h"
#include "UEXDataManager.h"
#include "UEEntityOperation.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
#define   PDMSENTITY_XDATA    "PDMSXData"

SingleEntityOperation::SingleEntityOperation()
{

}

SingleEntityOperation::~SingleEntityOperation()
{

}


BOOL SingleEntityOperation::ReadXData(AcDbHandle &EntityHandle, ElementType& nType,  UeObjectId &ObjId,  UeObjectId &OwnerId)
{
	UEXDataManager XDataManager(EntityHandle ,TRUE);
	if( !XDataManager.ReadUEXData() )
	{
		return FALSE;
	}
	UEXData* pXData = XDataManager.GetUEXData(PDMSENTITY_XDATA);
	if(pXData == NULL)
	{
		return FALSE;
	}

	int nTemp;
	pXData->AssertReadEnable();
	if( !pXData->ReadInt(nTemp) )
	{
		return FALSE;
	}
	nType =(ElementType) nTemp;
	
	if( !pXData->ReadInt(nTemp) )
	{
		return FALSE;
	}
	ObjId = nTemp ;

	if(!pXData->ReadInt(nTemp))
	{
		return FALSE;
	}
	OwnerId = nTemp;

	return TRUE;
}

BOOL SingleEntityOperation::WriteXData(AcDbHandle EntityHandle, ElementType nType,const UeObjectId &ObjId,const UeObjectId &OwnerId)
{
	UEXDataManager XDataManager(EntityHandle ,TRUE);	
	UEXData* pXData = XDataManager.GetUEXData(PDMSENTITY_XDATA);

	pXData->AssertWriteEnable();
	pXData->WriteInt(nType);
	pXData->WriteInt((INT)(ObjId));
	pXData->WriteInt((INT)(OwnerId));

	return XDataManager.WriteUEXData();
}

Acad::ErrorStatus SingleEntityOperation::TransformBy(AcDbHandle& EntityHandle ,AcGeMatrix3d &matrix)
{
	CUEEntityOperation EntityOperation;
	AcDbEntity* pEntity = EntityOperation.OpenEntityWrite(EntityHandle);
	ASSERT(pEntity!=NULL);

	Acad::ErrorStatus nState = pEntity->transformBy(matrix);
	
	if( nState!=Acad::eOk )
		return nState;
	return pEntity->close();
}

Acad::ErrorStatus SingleEntityOperation::HightLight(AcDbHandle& EntityHandle)
{
	CUEEntityOperation EntityOperation;
	AcDbEntity* pEntity = EntityOperation.OpenEntityWrite(EntityHandle);
	ASSERT(pEntity!=NULL);
	Acad::ErrorStatus nState = pEntity->highlight();
	if( nState!=Acad::eOk )
		return nState;
	return pEntity->close();
}
